<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
     <div style="margin: 10px 10px 10px 10px">
        <fieldset class="table-search-fieldset">
            <legend>多条件搜索</legend>
            <div class="layui-form layui-form-pane" lay-filter="goodsForm">
     <div class="layui-form-item">
        <label class="layui-form-label required">商品名称</label>
        <div class="layui-input-block">
            <input id="goodsName" type="text" name="goodsName" placeholder="请输入商品名称" value="" class="layui-input">           
        </div>
     </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">尺寸</label>
        <div class="layui-input-block">
            <input type="checkbox" name="standard1" value="小" title="小" >
            <input type="checkbox" name="standard2" value="中" title="中">
            <input type="checkbox" name="standard3" value="大" title="大">
        </div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label required">材质</label>
        <div class="layui-input-block">
            <input type="checkbox" name="material1" value="硅胶" title="硅胶">
            <input type="checkbox" name="material2" value="油泥" title="油泥">
            <input type="checkbox" name="material3" value="黏土" title="黏土">
            <input type="checkbox" name="material4" value="PVC" title="PVC">
        </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">商品权限</label>
      
      <div class="layui-input-block">
      
        <input type="checkbox" name="isin" value= "on" title="准入商品" checked>
        <input type="checkbox" name="isout" value ="on" title="准出商品" >
        <input type="checkbox" name="num"   value ="0" title="已清零商品" >
      </div>
    </div>
    
    <div class="layui-form-item">
       <label class="layui-form-label">已禁商品</label>
         <div class="layui-input-block">
           <input type="checkbox" name="notInOut"  value ="on" title="仅显示禁止出入商品" >
           <tip style="color:red">选中该选项准入商品与准出商品开关失效</tip>
         </div>
    </div>
    <div class="layui-form-item" >     
        <button id='searchbtn' type="button" class="layui-btn layui-btn-sm layui-btn-normal "  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>       
    </div>  
    <tip style="color:red">已弃用商品请在回收站进行管理</tip>  
</div>
  </fieldset>       
        <div class="layui-inline" style = "margin-top:8px">
            <button id="addGoods" type="button" class="layui-btn layui-btn-sm ">新增商品类</button>
            <button id="resetTable" type="button" class="layui-btn layui-btn-sm layui-btn-warm">重置表格</button>
        </div>
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        <script type="text/html" id="currentTableBar">
            <input  type="button" value = "编辑" class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="editGoods">
            <input  type="button" value = "办理入库" class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="editOrderIn" >
            <input  type="button" value = "办理出库" class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="editOrderOut" >
            <input type="button" value="单据明细" class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event= "orderDetail" >
            <input type="button" value= "弃用" class="layui-btn layui-btn-xs layui-btn-danger data-count-delete"  lay-event= "notUse" >
        </script>
    </div>
</div>
<script type="text/html" id='goodsForms'>
<div class="layui-form layuimini-form" lay-filter="goodsForms">
    <div class="layui-form-item">
        <label class="layui-form-label required">商品名称</label>
        <div class="layui-input-block">
            <input type="text" name="goodsName" lay-verify="required" lay-reqtext="商品名称不能为空" placeholder="请输入商品名称" value="" class="layui-input ">           
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">尺寸</label>
        <div class="layui-input-block">
            <input type="radio" name="standard" value="小" title="小" checked="">
            <input type="radio" name="standard" value="中" title="中">
            <input type="radio" name="standard" value="大" title="大">
        </div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label required">材质</label>
        <div class="layui-input-block">
            <input type="radio" name="material" value="硅胶" title="硅胶" checked="">
            <input type="radio" name="material" value="油泥" title="油泥">
            <input type="radio" name="material" value="黏土" title="黏土">
            <input type="radio" name="material" value="PVC" title="PVC">
        </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">权限</label>
      <div class="layui-input-block">
        <input type="checkbox" name="isin"  title="允许入库" checked>
        <input type="checkbox" name="isout" title="允许出库" checked>
       </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button id="savebtn" class="layui-btn layui-btn-normal">确认保存</button>
        </div>
    </div>
</div>
</script>

<script type="text/html" id='goodsFormsedit'>
<div class="layui-form layuimini-form" lay-filter="goodsFormsedit">
    <div class="layui-form-item">
        <input type='tel' name = 'id' hidden>  
        <label class="layui-form-label required">商品编号</label>
        <div class="layui-input-block">
            <input disabled type="text" name="goodsNo"  lay-verify="required"  value="" class="layui-btn layui-btn-primary">
            <tip sytle="color:red">不可编辑</tip>           
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">商品名称</label>
        <div class="layui-input-block">
            <input  disabled type="text" name="goodsName"  lay-verify="required"  value="" class="layui-btn layui-btn-primary">
            <tip sytle="color:red">不可编辑</tip>           
        </div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label required">尺寸</label>
        <div class="layui-input-block">
            <input  disabled type="text" name="standard" lay-verify="required"   value="" class="layui-btn layui-btn-primary">  
            <tip sytle="color:red">不可编辑</tip>          
        </div>
    </div>
    <div class="layui-form-item">
         <label class="layui-form-label required">材质</label>
         <div  disabled class="layui-input-block">
            <input disabled type="text" name="material" lay-verify="required" value="" class="layui-btn layui-btn-primary">
            <tip sytle="color:red">不可编辑</tip>            
         </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label">权限</label>
      <div class="layui-input-block">
        <input type="checkbox" name="isin"  title="允许入库" checked>
        <input type="checkbox" name="isout"  title="允许出库" checked>
       </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button id="editGoods" class="layui-btn layui-btn-normal">确认更新</button>
        </div>
    </div>
</div>
</script>

<script type="text/html" id='goodsFormsInOut'>
<div class="layui-form layuimini-form" lay-filter="goodsFormsInOut">
    <div class="layui-form-item">
        <input type='tel' name = 'id' hidden >  
        <label class="layui-form-label required">商品编号</label>
        <div class="layui-input-block">
            <input  disabled type="text" name="goodsNo"  lay-verify="required"  value="" class="layui-btn layui-btn-primary">
            <tip sytle="color:red">不可编辑</tip>           
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">商品名称</label>
        <div class="layui-input-block">
            <input  disabled type="text" name="goodsName"  lay-verify="required"  value="" class="layui-btn layui-btn-primary">
            <tip sytle="color:red">不可编辑</tip>           
        </div>
    </div>


    <div class="layui-form-item">
         <label class="layui-form-label required">生产厂家/订货商家</label>
         <div class="layui-input-block">
            <input   type="text" name="factory" lay-verify="required" value="" class="layui-input">          
         </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">尺寸</label>
        <div class="layui-input-block">
            <input  disabled type="text" name="standard" lay-verify="required"   value="" class="layui-btn layui-btn-primary">  
            <tip sytle="color:red">不可编辑</tip>          
        </div>
    </div>
    <div class="layui-form-item">
         <label class="layui-form-label required">材质</label>
         <div class="layui-input-block">
            <input  disabled  type="text" name="material" lay-verify="required" value="" class="layui-btn layui-btn-primary">
            <tip sytle="color:red">不可编辑</tip>            
         </div>
    </div>


    <div class="layui-form-item">
         <label class="layui-form-label required">出/入库价格</label>
         <div class="layui-input-block">
            <input type="text" name="singlePrice" lay-verify="required" value="" class="layui-input">         
         </div>
    </div>


    <div class="layui-form-item">
         <label class="layui-form-label required">数量</label>
         <div class="layui-input-block">
            <input  id = "inOutNum" type="text" name="num" lay-verify="required" value="" class="layui-input">
         </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label required">出/入日期</label>
        <div class="layui-input-block">
            <input type="date" name="dateio" value="" class="layui-date layui-btn layui-btn-primary" >         
        </div>
    </div>


    <div class="layui-form-item">
         <label class="layui-form-label required">送/取货单位</label>
         <div class="layui-input-block">
            <input  type="text" name="unit" lay-verify="required" value="" class="layui-input">         
         </div>
    </div>



    <div class="layui-form-item">
         <label class="layui-form-label required">送/提货人姓名</label>
         <div class="layui-input-block">
            <input  type="text" name="personName" lay-verify="required" value="" class="layui-input">         
         </div>
    </div>

   <div class="layui-form-item">
         <label class="layui-form-label required">送/提货人电话</label>
         <div class="layui-input-block">
            <input  type="text" name="tel" lay-verify="required" value="" class="layui-input">         
         </div>
    </div>
    <div class="layui-form-item">
         <label class="layui-form-label required">出/入库</label>
         <div id = "inOrOut"  class="layui-input-block">
            <input id = "show" disabled type="text" name="show" value="入库" class="layui-btn layui-btn-primary">
            <tip sytle="color:red ">不可编辑</tip>   
         </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button id="addOrder" class="layui-btn layui-btn-normal">确认添加</button>
        </div>
    </div>
</div>
</script>


<!--<script type="text/html" id='orderDetail'>-->

<!--<div style="margin: 10px 10px 10px 10px">-->
<!--<div class="layui-form layui-form-pane" lay-filter="orderDetail">-->
<!--    <div class="layui-form-item">-->
<!--      <label class="layui-form-label required">商品编号</label>-->
<!--      <div class="layui-input-block">-->
<!--            <input disabled type="text" name="goodsNo"  value=""  class="layui-btn layui-btn-primary">     -->
<!--      </div>-->
<!--    </div>-->
<!--    <div class="layui-form-item">-->
<!--        <label class="layui-form-label required">商品名称</label>-->
<!--        <div class="layui-input-block">-->
<!--            <input  disabled type="text" name="goodsName" value="" class="layui-btn layui-btn-primary">   -->
<!--        </div>-->
<!--    </div>-->
<!--    <div class="layui-form-item">-->
<!--        <label class="layui-form-label required">尺寸</label>-->
<!--        <div class="layui-input-block">-->
<!--            <input  disabled type="text" name="standard" value="" class="layui-btn layui-btn-primary">           -->
<!--        </div>-->
<!--    </div>-->
<!--    <div class="layui-form-item">-->
<!--         <label class="layui-form-label required">材质</label>-->
<!--         <div  disabled class="layui-input-block">-->
<!--            <input disabled type="text" name="material" value="" class="layui-btn layui-btn-primary">         -->
<!--         </div>-->
<!--    </div>-->
<!--<div>-->
<!--</div>-->
<!--   <table class="layui-hide" id="orderDetail"></table>-->
<!--</script>-->
<script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
   layui.use(['form', 'table','layer'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            layer = layui.layer;
        $('#resetTable').on('click',function(){
        	 table.render({
                 elem: '#currentTableId',
                 url: '/goods?',
                 where: {action:'selectGoodsList' },
                 cols: [[
                     {field: 'goodsNo', width: 200, title: '商品类别编号', sort: true },
                     {field: 'goodsName', width: 150, title: '商品名称', sort: true},
                     {field: 'standard', width: 60, title: '尺寸'},
                     {field: 'material', title: '材质', width:90},
                     {field: 'num', width: 80, title: '数量', sort: true},
                     {field: 'isin', width: 100, title: '入库许可', sort: true},
                     {field: 'isout', width: 100, title: '出库许可'},
                     {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
                 ]],                 
                 limits: [10, 15, 20, 25, 50, 100],
                 limit: 10,
                 page:true,
             });
        }).click();
        
        $('#addGoods').on('click',function(){
        	 console.log('this click success');
        	 var index = layer.open({
                 title: '添加商品种类',
                 type: 1,  // type 2可能会招致资源找不到
                 area: ['60%', '60%'],
                 content: $('#goodsForms').html(),
             });
        	 form.render();
        });


         // $.ajax('',
         //     success:function(){
         //
         // }
         // error:function(){
         //
         // }
         //
         // )


        // ***************************************************

        $('body').on('click','#savebtn',function(){
        	var data = form.val('goodsForms');
           layer.load(2);
            $.post('/goods?action=addGoods', data ,function(){
                layer.closeAll();
           	   // layer.closeAll('loading');
                // parent.layer.closeAll();
           	    $('#resetTable').click();
             });
        });
        //*******************************************************

        $('#searchbtn').on('click',function(){
           var data =form.val('goodsForm');
           console.log(data);
    	   table.render({
               elem: '#currentTableId',
               url: '/goods?action=selectGoodsList',
               where:data,       
               cols: [[
                   {field: 'goodsNo', width: 200, title: '商品类别编号',sort:true},
                   {field: 'goodsName', width: 150, title: '商品名称', sort: true},
                   {field: 'standard', width: 60, title: '尺寸'},
                   {field: 'material', title: '材质', width:90},
                   {field: 'num', width: 80, title: '数量', sort: true},
                   {field: 'isin', width: 100, title: '入库许可', sort: true},
                   {field: 'isout', width: 100, title: '出库许可'},
                   {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
               ]],                 
               limits: [10, 15, 20, 25, 50, 100],
               limit: 10,
               page:true,
           });
         });
         
         table.on('tool(currentTableFilter)', function (obj) {        	
            var data = obj.data;
            if (obj.event === 'editGoods') {
                var index = layer.open({
                    title: '编辑商品类',
                    type: 1,
                    area: ['60%', '60%'],
                    content: $('#goodsFormsedit').html(),                  
                });
                form.render();
                form.val('goodsFormsedit',{
                  	goodsNo : data.goodsNo,
                  	goodsName:data.goodsName,
                  	standard: data.standard,
                  	material: data.material,
                  	id:data.id,
                });
            } else if (obj.event === 'editOrderIn') {
            	  console.log(data);         
            	  if(data.isin === "允许入库"){
            		  var index = layer.open({
                          title: '出/入库单据办理',
                          type: 1,
                          area: ['80%', '80%'],
                          content: $('#goodsFormsInOut').html(),
                      });
                	  form.render();        
                	  form.val('goodsFormsInOut',data);
                	  $('#show').val("入库");
            	  }else{
            		  layer.confirm('该类商品已禁止入库');
            	  }
            }else if (obj.event==="editOrderOut"){
            	currentNum  = parseInt(data.num);
            	if(data.isout==="允许出库"){
            		layer.open({
            			 title: '出/入库单据办理',
                         type: 1,
                         area: ['80%', '80%'],
                         content: $('#goodsFormsInOut').html(),
            		});
            		form.render();
            		form.val('goodsFormsInOut',data);
                	$('#show').val("出库");
            	}else{
            		 layer.confirm('该类商品已禁止出库');
            	}	
            }else if(obj.event==="orderDetail"){
                   sessionStorage.setItem('datas',JSON.stringify(data));
                   layer.open({
                       title : "商品类相关单据明细",
                       type : 2,
                       area: ["90%" ,"90%"],
                       content:'../pageAdminUtil/orderDetail.html',
                   });
            } else if (obj.event === 'notUse') {
                   if(data.num != 0 ){
                       layer.confirm('该商品数目不为0，不能弃用');
                   }else{
                       layer.confirm('真的要弃用吗？',function(){
                           console.log(data.goodsNo);
                           layer.load(2);
                           $.post('/goods?action=updateGoodsToNotUse&goodsNo='+data.goodsNo, function() {
                               layer.closeAll();
                               $('#resetTable').click();
                           });
                       });
                   }
            }
        });

        $('body').on('click','#addOrder',function(){
        	 var data = form.val('goodsFormsInOut');
        	 console.log(data);
        	 if(data.show ==="入库"){
        		 data.status = "in";
            	 console.log(data.num);
            	 if( parseInt(data.num)<=0){ 
            		 layer.confirm('入库数量不能低于0');
            	 }   else  {
            		  console.log(data);
                       layer.load(2);
                 	  $.post('/orders?action=addOrder',data,function(){
                 		layer.closeAll();
                 		$('#resetTable').click();
                 	});      	
            	 }
        	 }
        	 else if(data.show === "出库"){
        		 data.status = "out";
            	 console.log(data.num);
            	 console.log(data);
                 if(parseInt(data.num)>=0){
                     layer.confirm('出库数目应该为负数');
                 }
                 else if(currentNum < -parseInt (data.num)){
            		 layer.confirm("出货数量不能超出存货数量");
            	 }
            	 else{
            		// data.num = -parseInt(data.num)+"";
                     console.log(data.num);
            		 console.log(data.status);
            		//  console.log(data);
                     layer.load(2);
            		$.post('/orders?action=addOrder',data,function(){
                 		layer.closeAll();
                 		$('#resetTable').click();
                 	});  	
            	 }
        	 }
        });

        $('body').on('click', '#editGoods' , function(){
        	var data = form.val('goodsFormsedit');
            console.log(data);
            layer.load(2);
            $.post('goods?action=updateGoodsInOut',data, function(){
         		layer.closeAll();
         		$('#resetTable').click();
         	});
       });
    });
</script>
</body>
</html>